import { useModel } from '@umijs/max';
import { Select } from 'antd';
import { useMemo } from 'react';

const RolePicker = (props: any) => {
  const { list } = useModel('role');
  const options = useMemo(() => {
    return list.map((v: any) => ({
      label: v.name,
      value: v.id,
    }));
  }, [list]);
  // 排除默认空字符串 导致不显示 placeholder 的问题
  const value = props.value === '' ? undefined : props.value;
  return (
    <Select
      placeholder={'请选择角色'}
      showSearch
      {...props}
      value={value}
      options={options}
    />
  );
};

export default RolePicker;
